<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue使用之同级传值</title>
    <script src="../vue.min.js" type="text/javascript"></script>
</head>
<body>
<div id="app">
    <boy-component></boy-component>
    <girl-component></girl-component>
</div>

<script type="text/javascript">
    var bus=new Vue();
    var boyComponent = {
        template: `<button @click="send">发送</button>`,
        data(){
            return {
                info:'hello,我是boy组件'
            }
        },
        methods: {
            send:function () {
                bus.$emit('boy',this.info)
            }
        }
    }
    var girlComponent = {
        template: `<div>{{msg}}</div>`,
        data(){
            return {
                msg:''
            }
        },
        created:function(){
            var me=this
            bus.$on('boy',function (info) {
                me.msg=info
            })
        }
    }

    var app=new Vue({
        el: '#app',
        components:{
            boyComponent,
            girlComponent
        }
    })
</script>
</body>
</html>